package com.tedu.movie.controller;

import com.tedu.movie.pojo.*;

import com.tedu.movie.service.TorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;



@CrossOrigin
@RestController
public class TorderController {
    @Autowired

    TorderService torderService;

    @RequestMapping("/torder/buy")
    public ServerResult buy(Torder torder){
        boolean isSuccess = torderService.buy(torder);
        ServerResult serverResult=null;
        if(isSuccess){
            serverResult=new ServerResult(0,"购票成功",null);

        }else{
            serverResult=new ServerResult(1,"购票失败",null);

        }
        return  serverResult;
    }

    @RequestMapping("/torder/updateTorder")
    public ServerResult updateTorder(Torder torder){
        boolean isSuccess = torderService.updateTorder(torder);
        if(isSuccess){
            return new ServerResult(0,"更新成功",null);
        }else {return new ServerResult(1,"更新失败",null);}

    }
    @RequestMapping("/torder/deleteTorder")
    public ServerResult deleteTorder(Integer id){
        boolean isSuccess = torderService.deleteTorder(id);
        if(isSuccess){
            return new ServerResult(0,"删除成功",null);
        }else {return new ServerResult(1,"删除失败",null);}
    }

    @RequestMapping("/torder/selectAll")
    public ServerResult selectAll(){
        List<TorderItemVO> list = torderService.selectAll();
        return new ServerResult(0,"查询成功",list);

    }
    @RequestMapping("/torder/insertTorder")
    public  ServerResult insertTorder(Torder torder){
        boolean isSuccess =torderService.insertTorder(torder);
        if(isSuccess){
            return new ServerResult(0,"添加成功",null);
        }else{
            return new ServerResult(1,"添加失败",null);
        }
    }

    @RequestMapping("/torder/selectById")
    public ServerResult selectById(Integer id){
        Torder torder = torderService.selectById(id);
        return new ServerResult(0,"查询成功",torder);
    }

    @RequestMapping("/torder/selectByItemId")
    public ServerResult selectByItemId(Integer itemId){
        List<Torder> list = torderService.selectByItemId(itemId);
        return new ServerResult(0,"查询成功",list);

    }
}
